package com.yangyang.androidconnect.config;

import com.yangyang.androidconnect.common.ApiResult;
import com.yanzhenjie.andserver.annotation.Resolver;
import com.yanzhenjie.andserver.framework.ExceptionResolver;
import com.yanzhenjie.andserver.http.HttpRequest;
import com.yanzhenjie.andserver.http.HttpResponse;

/**
 * 全局异常处理
 */
@Resolver
public class AppExceptionResolver implements ExceptionResolver {

    @Override
    public void onResolve(HttpRequest request, HttpResponse response, Throwable e) {
        ApiResult<Object> error = ApiResult.error(e.getMessage());
        response.setBody(new FastjsonBody(error));
        response.setStatus(500);
    }
}